//
//  LiveGoodsDetailViewController.m
//  PrintPort
//
//  Created by hy002 on 2017/12/29.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "LiveGoodsDetailViewController.h"
#import "GoodsModel.h"
#import "SizeListModel.h"
#import "SizeDetailModel.h"
#import "ImagelistModel.h"
#import "SDCycleScrollView.h"
#import <QuartzCore/QuartzCore.h>
#import "JSBadgeView.h"
#import "FeedBackViewController.h"
#import "BuyNowViewController.h"
#import "LookParameterViewController.h"

static NSString *cellPath = @"GoodsDetailsCell";
static NSString *ggCellPath = @"ggCell";
static NSString *parmCellPath = @"parmCell";

@interface LiveGoodsDetailViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UIWebViewDelegate,UIScrollViewDelegate,UITextFieldDelegate>
{
    CGFloat heightX;
    CGFloat classHeight;
    UIScrollView *titScrollview;
    UIView *bottonLine;
    UILabel *tongjiLab;
    UIView *classificationView;
    UIView *specificationsView;
    UIView *closeNumView;
    UITextField *numTextfield;
    UILabel *pricelab;
    UIButton *lookBtn;
    UILabel *integralLab;
    
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)UITableView *ggTableview;
@property (nonatomic, strong)UITableView *parameterTableview;
@property (nonatomic, strong)GoodsModel *model;
@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong)UIWebView *webView;
@property (nonatomic, strong)UIView *closeGgView;
@property (nonatomic, strong)NSArray *typeGgAry;
@property (nonatomic, strong)NSMutableDictionary *closeGoodsDic;
@property (nonatomic, assign)NSInteger indexrow;
@property (nonatomic, strong)NSMutableDictionary *priceDic;
@property (nonatomic, assign)BOOL isShopCar;
@property (nonatomic, assign)NSInteger allNumber;
@property (nonatomic, assign)CGFloat allPrice;
@property (nonatomic, assign)CGFloat allInteger;
@property (nonatomic, strong)UIView *parameterView;
@property (nonatomic, strong)NSArray *parameterAry;
@property (nonatomic, strong)NSString *csID;
@property (nonatomic, assign)NSInteger classType;
@property (nonatomic, assign)NSInteger speciType;
@property (nonatomic, assign)BOOL isClose;

@end

@implementation LiveGoodsDetailViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jianpanhuishou:) name:UIKeyboardWillHideNotification object:nil];
    self.navigationController.navigationBar.hidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _closeGoodsDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _priceDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _indexrow = 0;
    _allNumber = 0;
    _allPrice = 0;
    _allInteger = 0;
    _speciType = 0;
    _classType = 0;
    _csID = @"0";
    [self creatUI];
    [self requestProductSelect];
}

- (void)creatUI
{
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.hidden = YES;
    heightX = 0;
    if (SCREEN_HEIGHT == 812)
    {
        heightX = 34;
    }
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, -STATUSBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT+STATUSBAR_HEIGHT-45*displaywidth-heightX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.tag = 11;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300*displaywidth)];
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300*displaywidth) delegate:self placeholderImage:nil];
    _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    _cycleScrollView.delegate = self;
    //是否自动轮播
    _cycleScrollView.autoScroll = YES;//是否自动轮播 bannerImageViewContentMode
    //图片样式
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.clipsToBounds = YES;
    _cycleScrollView.currentPageDotColor = ThemeColor;
    _cycleScrollView.pageDotColor = [UIColor whiteColor];
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    [headerView addSubview:_cycleScrollView];
    
    self.tableview.tableHeaderView = headerView;
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, STATUSBAR_HEIGHT, SCREEN_WIDTH, 60*displaywidth)];
    topView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:topView];
    
    UIButton *backBtn = [ZCControl createButtonWithFrame:CGRectMake(10*displaywidth, 10*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"fanhui222" Target:self Action:@selector(backAction) Title:nil Font:12.0];
    backBtn.backgroundColor = [UIColor clearColor];
    [topView addSubview:backBtn];
    
//    UIButton *shareBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-110*displaywidth, 10*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"fenxiang" Target:self Action:@selector(shareAction) Title:nil Font:12.0];
//    shareBtn.backgroundColor = [UIColor clearColor];
//    [topView addSubview:shareBtn];
    
    UIButton *feedbackBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 10*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@"yijianfankui" Target:self Action:@selector(feedbackAction) Title:nil Font:12.0];
    feedbackBtn.backgroundColor = [UIColor clearColor];
    [topView addSubview:feedbackBtn];
    
    UIView *bottonView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-45*displaywidth-heightX, SCREEN_WIDTH, 45*displaywidth)];
    bottonView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottonView];
    
    UIButton *addShopBtn = [ZCControl createButtonWithFrame:CGRectMake(0 , 0, SCREEN_WIDTH/2, 45*displaywidth) ImageName:nil Target:self Action:@selector(addShopAction) Title:@"加入购物车" Font:15.0];
    [addShopBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
    addShopBtn.backgroundColor = [UIColor whiteColor];
    [bottonView addSubview:addShopBtn];
    UIButton *BuyBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH/2 , 0, SCREEN_WIDTH/2, 45*displaywidth) ImageName:nil Target:self Action:@selector(buyAction) Title:@"立即购买" Font:15.0];
    [BuyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    BuyBtn.backgroundColor = ThemeColor;
    [bottonView addSubview:BuyBtn];
    if (_isTeHui)
    {
        addShopBtn.hidden = YES;
        BuyBtn.frame = CGRectMake(0 , 0, SCREEN_WIDTH, 45*displaywidth);
    }
}

- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBar.hidden = NO;
}

//分享
//- (void)shareAction
//{
//    
//}

//反馈
- (void)feedbackAction
{
    FeedBackViewController *vc = [[FeedBackViewController alloc] init];
    vc.pladerStr = @"请输入遇到的问题或建议...";
    vc.titleStr = @"意见反馈";
    [self.navigationController pushViewController:vc animated:YES];
}

//加入购物车
- (void)addShopAction
{
    _isShopCar = YES;
    _closeGgView.hidden = NO;
}
//立即购买
- (void)buyAction
{
    _parameterView.hidden = YES;
    _isShopCar = NO;
    _closeGgView.hidden = NO;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView.tag == 11)
    {
        return 4;
        
    }
    else
    {
        return _parameterAry.count;
    }
 
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 11)
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (_model)
        {
            UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
            lineV.backgroundColor = LinesColor;
            [cell.contentView addSubview:lineV];
            if (indexPath.row == 0)
            {
                UILabel *titleLabel = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 0, SCREEN_WIDTH- 40*displaywidth, 30*displaywidth) Font:14.0 Text:_model.productName Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:titleLabel];

//                UIButton *priceBtn = [ZCControl createButtonWithFrame:CGRectMake(20*displaywidth, 45*displaywidth, 140*displaywidth, 30*displaywidth) ImageName:@"jifen" Target:nil Action:nil Title:string(@" ", _model.price) Font:14.0];
//                priceBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//                priceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//                priceBtn.backgroundColor = [UIColor clearColor];
//                [priceBtn setTitleColor:priceColor forState:UIControlStateNormal];
//                [cell.contentView addSubview:priceBtn];
                UILabel *moneyLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 45*displaywidth, 140*displaywidth, 30*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"%@",_model.priceDescribe] Color:RGB(241, 90, 36)];
                CGRect abounds = [moneyLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-200*displaywidth, 30*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)} context:nil];
                CGFloat width1 = abounds.size.width+20;
                moneyLab.frame = CGRectMake(20*displaywidth, 45*displaywidth, width1, 30*displaywidth);
                [cell.contentView addSubview:moneyLab];
                if (!_isTeHui)
                {
                    moneyLab.text = [NSString stringWithFormat:@"%@ +",_model.priceDescribe];
                    UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(width1+25*displaywidth, 50*displaywidth, 120*displaywidth, 20*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",_model.integral] Color:[UIColor whiteColor]];
                    integralLab.textAlignment = NSTextAlignmentCenter;
                    integralLab.layer.cornerRadius = 2;
                    integralLab.layer.masksToBounds = YES;
                    integralLab.backgroundColor = RGB(24, 159, 186);
                    [cell.contentView addSubview:integralLab];
                    CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
                    CGFloat width2 = bounds1.size.width+10;
                    if (bounds1.size.width > 120*displaywidth)
                    {
                        width2 = 120*displaywidth;
                    }
                    integralLab.frame = CGRectMake(width1+25*displaywidth, 50*displaywidth, width2, 20*displaywidth);
                }
                
                
                UILabel *historyLabel = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/2+20*displaywidth, 50*displaywidth, 100*displaywidth, 20*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@购买",_model.productSales] Color:RGB(179, 179, 179)];
                [cell.contentView addSubview:historyLabel];
                
                UILabel *numLabel = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-115*displaywidth, 50*displaywidth, 100*displaywidth, 20*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@库存",_model.productStock] Color:RGB(179, 179, 179)];
                numLabel.textAlignment = NSTextAlignmentCenter;
                [cell.contentView addSubview:numLabel];
            }
            else if (indexPath.row == 1 || indexPath.row == 2)
            {
                NSString *name = @"选择分类";
                if (indexPath.row == 2)
                {
                    name = @"商品参数";
                }
                UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 0, 140*displaywidth, 30*displaywidth) Font:14.0 Text:name Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:nameLab];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }
            else
            {
                UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10*displaywidth)];
                grayView.backgroundColor = BacksColor;
                [cell.contentView addSubview:grayView];
                UILabel *Label = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 10*displaywidth, 140*displaywidth, 30*displaywidth) Font:14.0 Text:@"商品详情" Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:Label];
                if (![_model.proDescribe isEqualToString:@""])
                {
                    if (!self.webView)
                    {
                        [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
                        _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 40*displaywidth, SCREEN_WIDTH, 200*displaywidth)];
                        _webView.delegate = self;
                        _webView.scrollView.scrollEnabled = NO;
                        //预先加载url
                        [self.webView loadHTMLString:_model.proDescribe baseURL:nil];
                    }
                    [cell.contentView addSubview:_webView];
                    
                }
                
            }
        }
        return cell;
    }
    else
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:parmCellPath];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (_parameterAry.count > 0)
        {
            NSDictionary *dic = _parameterAry[indexPath.row];
            UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 135*displaywidth, 40*displaywidth) Font:14.0 Text:dic[@"name"] Color:RGB(128, 128, 128)];
            [cell.contentView addSubview:nameLab];
            UILabel *tostLab = [ZCControl createLabelWithFrame:CGRectMake(150*displaywidth, 0, SCREEN_WIDTH-165*displaywidth, 40*displaywidth) Font:14.0 Text:dic[@"value"] Color:BlaTiColor];
            [cell.contentView addSubview:tostLab];
            UIView *lineAAview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1*displaywidth)];
            lineAAview.backgroundColor = LinesColor;
            [cell.contentView addSubview:lineAAview];
            
        }
        return cell;
    }
    
    
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    //获取到webview的高度
    NSString *js= @"var script = document.createElement('script');"
    "script.type = 'text/javascript';"
    "script.text = \"function ResizeImages() { "
    "var myimg,oldwidth;"
    "var maxwidth = %f;"
    "for(i=0;i <document.images.length;i++){"
    "myimg = document.images[i];"
    "if(myimg.width > maxwidth){"
    "oldwidth = myimg.width;"
    "myimg.width = %f;"
    "}"
    "}"
    "}\";"
    "document.getElementsByTagName('head')[0].appendChild(script);";
    js=[NSString stringWithFormat:js,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.width-15];
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    self.webView.frame = CGRectMake(self.webView.frame.origin.x,self.webView.frame.origin.y, SCREEN_WIDTH, height+40*displaywidth);
    [self.tableview reloadData];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 66)
    {
        _parameterView.hidden = YES;
        return;
    }
    else
    {
        if (indexPath.row == 1)
        {
            if (_isTeHui)
            {
                _isShopCar = NO;

            }
            else
            {
                _isShopCar = YES;

            }
            _closeGgView.hidden = NO;
        }
        else if (indexPath.row == 2)
        {
            [self creatParameterView];
        }
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 11)
    {
        if (indexPath.row == 0)
        {
            return 80*displaywidth;
        }
        else if (indexPath.row == 3)
        {
            return _webView.frame.size.height+40*displaywidth;
        }
        else
        {
            return 30*displaywidth;
        }
    }
    else
    {
        return 40*displaywidth;
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (tableView.tag == 66)
    {
        return 40*displaywidth;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *myView = [[UIView alloc] init];
    if (tableView.tag == 66)
    {
        myView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 40*displaywidth);
        myView.backgroundColor = [UIColor whiteColor];
        UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40*displaywidth) Font:14.0 Text:@"商品参数" Color:BlaTiColor];
        titLab.textAlignment = NSTextAlignmentCenter;
        [myView addSubview:titLab];
    }
    return myView;
}


//减少数量
- (void)deleteBtnAction:(UIButton *)btn
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
    if (!_isClose)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:self.view];
        return;
    }
    NSInteger num = [numTextfield.text integerValue];
    if (num < 2)
    {
        return;
    }
    numTextfield.text = s_Integer(num-1);
    [self tongjiNumberAndMoney];

}

//添加数量
- (void)addBtnAction:(UIButton *)btn
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
    if (!_isClose)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:sharedDelegate.window];
        return;
    }
    NSInteger num = [numTextfield.text integerValue];
    numTextfield.text = s_Integer(num+1);
    [self tongjiNumberAndMoney];
}



- (void)tongjiNumberAndMoney
{
    NSInteger zongNum = [numTextfield.text integerValue];
    NSArray *producListAry = _model.productSizeList;
    SizeListModel *sizeModel = producListAry[_classType];
    NSArray *SizeDetailAry = sizeModel.productSizeDetailList;
    if (SizeDetailAry.count == 0)
    {
        [LTools showMBProgressWithText:@"该类型暂无规格商品可选" addToView:self.view];
        return;
    }
    SizeDetailModel *detailmodel = SizeDetailAry[_speciType];
    CGFloat price = [detailmodel.price floatValue];
    CGFloat zongPrice = price*zongNum;
    CGFloat integral = [detailmodel.integral floatValue];
    CGFloat zongIntegral = integral*zongNum;

    _allNumber = zongNum;
    _allPrice = zongPrice;
    _allInteger = zongIntegral;
    NSString *tongjiStr = [NSString stringWithFormat:@"共 %ld 件商品  合计: ￥%.2lf元 + %.0lf积分",zongNum,zongPrice,zongIntegral];
    if (_isTeHui)
    {
        tongjiStr = [NSString stringWithFormat:@"共 %ld 件商品  合计: ￥%.2lf元",zongNum,zongPrice];
    }
    tongjiLab.text = tongjiStr;
    NSString *zonNumStr = [NSString stringWithFormat:@"%ld",zongNum];
    NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
    if (!_isTeHui)
    {
        NSRange titleRange = [[noteString string]rangeOfString:[NSString stringWithFormat:@" %.0lf",zongIntegral]];
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:titleRange];

    }
    NSRange stringRange = NSMakeRange(2, zonNumStr.length);
    NSRange stringRange22 = [[noteString string]rangeOfString:[NSString stringWithFormat:@" ￥%.2lf",zongPrice]];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
    [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
    [tongjiLab setAttributedText:noteString];
    [_closeGoodsDic removeAllObjects];
    if (zongPrice > 0)
    {
        pricelab.text = [NSString stringWithFormat:@"￥%.2lf元",price];
        if (!_isTeHui)
        {
            pricelab.text = [NSString stringWithFormat:@"￥%.2lf元 +",price];
            integralLab.text = [NSString stringWithFormat:@"%@积分",detailmodel.integral];
        }
        NSMutableDictionary *newDic = [NSMutableDictionary dictionaryWithCapacity:0];
        [newDic setObject:s_Integer(zongNum) forKey:detailmodel.ID];
        [_closeGoodsDic setObject:newDic forKey:detailmodel.productSizeId];
    }
    else
    {
        pricelab.text = _model.priceDescribe;
        if (!_isTeHui)
        {
            pricelab.text = [_model.priceDescribe stringByAppendingString:@" +"];
            integralLab.text = [NSString stringWithFormat:@"%@积分",_model.integral];
        }
        
        
    }
    if (!_isTeHui)
    {
        CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
        CGFloat width1 = bounds1.size.width+10;
        if (bounds1.size.width > 120*displaywidth)
        {
            width1 = 120*displaywidth;
        }
        integralLab.frame = CGRectMake(100*displaywidth, 70*displaywidth, width1, 15*displaywidth);
    }
    
    
}

- (void)requestProductSelect
{
    WEAKSELF;
    NSDictionary *dic = @{@"id":[NSString stringWithFormat:@"%@",_idStr]};
    [HYBaseHandler requestProductSelectParmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             _model = [GoodsModel mj_objectWithKeyValues:obj[@"data"]];
             dispatch_async(dispatch_get_main_queue(), ^{
                 [weakSelf.tableview reloadData];
                 if (_model.productImgList.count > 0)
                 {
                     NSMutableArray *imgArray = [NSMutableArray arrayWithCapacity:0];
                     for (ImagelistModel *imgModel in _model.productImgList)
                     {
                         [imgArray addObject:imgModel.imgUrl];
                     }
                     _cycleScrollView.imageURLStringsGroup = imgArray;
                 }
                 [weakSelf creatCloseGgView];
                 
             });
             
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}


- (void)creatParameterView
{
    if (!self.parameterView)
    {
        _parameterAry = [self dictionaryWithJsonString:_model.attributeJson];
        self.parameterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _parameterView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_parameterView];
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped22:)];
        tap2.cancelsTouchesInView = NO;
        [_parameterView addGestureRecognizer:tap2];
        self.parameterTableview = [[UITableView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-240*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 200*displaywidth) style:UITableViewStylePlain];
        _parameterTableview.delegate = self;
        _parameterTableview.dataSource = self;
        _parameterTableview.tag = 66;
        _parameterTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _parameterTableview.backgroundColor = [UIColor whiteColor];
        [_parameterView addSubview:_parameterTableview];
        
        UIView *whiteview = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-40*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 40*displaywidth+SCREER_HeiX)];
        whiteview.backgroundColor = [UIColor whiteColor];
        [_parameterView addSubview:whiteview];
        
        UIButton *BuyBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40*displaywidth) ImageName:nil Target:self Action:@selector(buyAction) Title:@"立即购买" Font:15.0];
        [BuyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        BuyBtn.backgroundColor = ThemeColor;
        [whiteview addSubview:BuyBtn];
        
    }
    _parameterView.hidden = NO;
    
}

- (void)viewTapped22:(UITapGestureRecognizer*)tap2
{
    _parameterView.hidden = YES;

}

- (void)creatCloseGgView
{
    if (!self.closeGgView)
    {
        self.closeGgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _closeGgView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_closeGgView];
        
        UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-315*displaywidth-SCREER_HeiX, SCREEN_HEIGHT, 315*displaywidth+SCREER_HeiX)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [_closeGgView addSubview:whiteView];
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
        tap1.cancelsTouchesInView = NO;
        [whiteView addGestureRecognizer:tap1];
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, 70*displaywidth, 70*displaywidth) ImageName:@""];
        if (_model.productImgList.count > 0)
        {
            ImagelistModel *imgModel = _model.productImgList[0];
            [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
        }
        [whiteView addSubview:imgView];
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 10*displaywidth, SCREEN_WIDTH-145*displaywidth, 30*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@",_model.productName] Color:RGB(77, 77, 77)];
        titlab.lineBreakMode = NSLineBreakByTruncatingTail;
        [whiteView addSubview:titlab];
        UIButton *backGGBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-30*displaywidth, 10*displaywidth, 20*displaywidth, 20*displaywidth) ImageName:@"guanbi" Target:self Action:@selector(backGGAction) Title:nil Font:12.0];
        backGGBtn.backgroundColor = [UIColor clearColor];
        [whiteView addSubview:backGGBtn];
        pricelab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 50*displaywidth, SCREEN_WIDTH-145*displaywidth, 20*displaywidth) Font:14.0 Text:_model.priceDescribe Color:RGB(241, 90, 36)];
        [whiteView addSubview:pricelab];
        if (!_isTeHui)
        {
            pricelab.text = [_model.priceDescribe stringByAppendingString:@" +"];
            integralLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 70*displaywidth, 120*displaywidth, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",_model.integral] Color:[UIColor whiteColor]];
            integralLab.textAlignment = NSTextAlignmentCenter;
            integralLab.layer.cornerRadius = 2;
            integralLab.layer.masksToBounds = YES;
            integralLab.backgroundColor = RGB(24, 159, 186);
            [whiteView addSubview:integralLab];
            CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
            CGFloat width1 = bounds1.size.width+10;
            if (bounds1.size.width > 120*displaywidth)
            {
                width1 = 120*displaywidth;
            }
            integralLab.frame = CGRectMake(100*displaywidth, 70*displaywidth, width1, 15*displaywidth);
            lookBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 67.5*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(lookAction) Title:@"查看参数>>" Font:12.0];
            [lookBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
            lookBtn.hidden = YES;
            [whiteView addSubview:lookBtn];
        }
        
        
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 99*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview.backgroundColor = LinesColor;
        [whiteView addSubview:lineview];
        
        titScrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100*displaywidth, SCREEN_WIDTH, 170*displaywidth)];
        titScrollview.backgroundColor = [UIColor whiteColor];
        titScrollview.delegate = self;
        titScrollview.contentOffset = CGPointMake(0, 0);
        titScrollview.pagingEnabled = NO;
        titScrollview.bounces = NO;
        titScrollview.showsHorizontalScrollIndicator = YES;
        [whiteView addSubview:titScrollview];
        classificationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300*displaywidth)];
        classificationView.backgroundColor = [UIColor whiteColor];
        [titScrollview addSubview:classificationView];
        CGFloat h2 = 35*displaywidth;
        CGFloat h22 = 35*displaywidth;
        if (_model.productSizeList.count > 0)
        {
            NSArray *producListAry = _model.productSizeList;
            UILabel *typeLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 100*displaywidth, 29*displaywidth) Font:14.0 Text:@"类型" Color:BlaTiColor];
            [classificationView addSubview:typeLab];
            CGFloat width = SCREEN_WIDTH-30*displaywidth;
            CGFloat w2 = 0;
            for (int i = 0; i < producListAry.count; i++)
            {
                SizeListModel *sizeModel = producListAry[i];
                NSString *typename = sizeModel.productSizeName;
                UIButton *tasteBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth+i*75*displaywidth, h2, 60*displaywidth, 25*displaywidth) ImageName:nil Target:self Action:@selector(tasteBtnAction:) Title:typename Font:12.0];
                tasteBtn.tag = 500+i;
                NSDictionary *attributes = @{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)};
                CGFloat length = [typename boundingRectWithSize:CGSizeMake(width-20*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
                tasteBtn.frame = CGRectMake(15*displaywidth + w2, h2, length + 15*displaywidth , 25*displaywidth);
                if (length > width-20*displaywidth)
                {
                    length = width-20*displaywidth;
                }
                if(15*displaywidth + w2 + length + 15*displaywidth > width){
                    w2 = 0; //换行时将w置为0
                    h2 = h2 + tasteBtn.frame.size.height + 10*displaywidth;//距离父视图也变化
                    tasteBtn.frame = CGRectMake(15*displaywidth + w2, h2, length + 15*displaywidth, 25*displaywidth);//重设button的frame
                }
                w2 = tasteBtn.frame.size.width + tasteBtn.frame.origin.x;
                UIColor *bordercolor2 = RGB(222, 222, 222);
                UIColor *titcolor2 = RGB(77, 77, 77);
                [tasteBtn setTitleColor:titcolor2 forState:UIControlStateNormal];
                tasteBtn.layer.cornerRadius = 12.5*displaywidth;
                tasteBtn.layer.masksToBounds = YES;
                tasteBtn.backgroundColor = bordercolor2;
                [classificationView addSubview:tasteBtn];
                
            }
            h2+=45*displaywidth;
            classHeight = h2;
            classificationView.frame = CGRectMake(0, 0, SCREEN_WIDTH, h2);
            titScrollview.contentSize = CGSizeMake(SCREEN_WIDTH, h2+45*displaywidth);
            specificationsView = [[UIView alloc] initWithFrame:CGRectMake(0, h2, SCREEN_WIDTH, 300*displaywidth)];
            specificationsView.backgroundColor = [UIColor whiteColor];
            [titScrollview addSubview:specificationsView];
            SizeListModel *sizeModel = producListAry[0];
            NSArray *SizeDetailAry = sizeModel.productSizeDetailList;
            if (SizeDetailAry.count > 0)
            {
                [self reloadSpeciView:SizeDetailAry];
            }
            h22 = specificationsView.frame.size.height;
            closeNumView = [[UIView alloc] initWithFrame:CGRectMake(0, h22+h2, SCREEN_WIDTH, 45*displaywidth)];
            closeNumView.backgroundColor = [UIColor whiteColor];
            [titScrollview addSubview:closeNumView];
            UIView *lineNView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1*displaywidth)];
            lineNView.backgroundColor = LinesColor;
            [closeNumView addSubview:lineNView];
            UILabel *buyNumLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 1*displaywidth, SCREEN_WIDTH-145*displaywidth, 44*displaywidth) Font:14.0 Text:@"购买数量" Color:BlaTiColor];
            [closeNumView addSubview:buyNumLab];
            UIView *numView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-140*displaywidth, 8*displaywidth, 110*displaywidth, 30*displaywidth)];
            numView.backgroundColor = [UIColor whiteColor];
            numView.layer.cornerRadius = 2;
            numView.layer.masksToBounds = YES;
            numView.layer.borderColor = RGB(204, 204, 204).CGColor;
            numView.layer.borderWidth = 1;
            [closeNumView addSubview:numView];
            UIView *line01 = [[UIView alloc] initWithFrame:CGRectMake(29*displaywidth, 0, 1*displaywidth, 30*displaywidth)];
            line01.backgroundColor = RGB(204, 204, 204);
            [numView addSubview:line01];
            UIView *line02 = [[UIView alloc] initWithFrame:CGRectMake(80*displaywidth, 0, 1*displaywidth, 30*displaywidth)];
            line02.backgroundColor = RGB(204, 204, 204);
            [numView addSubview:line02];
            UIButton *deleteBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, 30*displaywidth, 30*displaywidth) ImageName:nil Target:self Action:@selector(deleteBtnAction:) Title:@"-" Font:16.0];
            deleteBtn.backgroundColor = [UIColor clearColor];
            [deleteBtn setTitleColor:RGB(179, 179, 179) forState:UIControlStateNormal];
            [numView addSubview:deleteBtn];
            UIButton *addBtn = [ZCControl createButtonWithFrame:CGRectMake(80*displaywidth, 0, 30*displaywidth, 30*displaywidth) ImageName:nil Target:self Action:@selector(addBtnAction:) Title:@"+" Font:16.0];
            addBtn.backgroundColor = [UIColor clearColor];
            [addBtn setTitleColor:RGB(179, 179, 179) forState:UIControlStateNormal];
            [numView addSubview:addBtn];
            UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(30*displaywidth, 0, 50*displaywidth, 30*displaywidth) placeholder:@"" passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
            [textfield setValue:RGB(77, 77, 77) forKeyPath:@"_placeholderLabel.textColor"];
            textfield.textColor = RGB(77, 77, 77);
            textfield.text = @"0";
            textfield.textAlignment = NSTextAlignmentCenter;
            textfield.delegate = self;
            textfield.keyboardType = UIKeyboardTypeNumberPad;
            [numView addSubview:textfield];
            numTextfield = textfield;
        }
        UIView *line33 = [[UIView alloc] initWithFrame:CGRectMake(0, 270*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        line33.backgroundColor = LinesColor;
        [whiteView addSubview:line33];
        NSString *tongjiStr = @"共 0 件商品  合计：￥0.00元 + 0积分";
        if (_isTeHui)
        {
            tongjiStr = @"共 0 件商品  合计：￥0.00元";
        }
        tongjiLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 275*displaywidth, SCREEN_WIDTH-135*displaywidth, 35*displaywidth) Font:14.0 Text:tongjiStr Color:RGB(77, 77, 77)];
        tongjiLab.textAlignment = NSTextAlignmentRight;
        NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:tongjiLab.text];
        NSRange stringRange = NSMakeRange(2, 1);
        NSRange stringRange22 = [[noteString string]rangeOfString:@"￥0.00"];
        if (!_isTeHui)
        {
            NSRange stringRange33 = NSMakeRange(tongjiLab.text.length-3, 1);
            [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange33];

        }
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange];
        [noteString addAttribute:NSForegroundColorAttributeName value:RGB(241, 90, 36) range:stringRange22];
        [tongjiLab setAttributedText:noteString];
        [whiteView addSubview:tongjiLab];
        UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 270*displaywidth, 100*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(soureAction) Title:@"确定" Font:16.0];
        soureBtn.backgroundColor = ThemeColor;
        [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [whiteView addSubview:soureBtn];
    }
    _closeGgView.hidden = YES;
}

//选择类型
- (void)tasteBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-500;
    for (id v in classificationView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            [button setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
            button.backgroundColor = RGB(222, 222, 222);
        }
    }
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = ThemeColor;
    if (index == _classType)
    {
        return;
    }
    _classType = index;
    _speciType = 0;
    _isClose = NO;
    if (_isProbject)
    {
        lookBtn.hidden = YES;
    }
    numTextfield.text = @"0";
    NSArray *producListAry = _model.productSizeList;
    SizeListModel *sizeModel = producListAry[index];
    NSArray *SizeDetailAry = sizeModel.productSizeDetailList;
    for (id subView in specificationsView.subviews)
    {
        [subView removeFromSuperview];
    }
    [self reloadSpeciView:SizeDetailAry];
    [self tongjiNumberAndMoney];
}

- (void)reloadSpeciView:(NSArray *)SizeDetailAry
{
    UILabel *typeBLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 100*displaywidth, 29*displaywidth) Font:14.0 Text:@"规格" Color:BlaTiColor];
    [specificationsView addSubview:typeBLab];
    CGFloat width = SCREEN_WIDTH-30*displaywidth;
    CGFloat w22 = 0;
    CGFloat h22 = 35*displaywidth;
    for (int i = 0; i < SizeDetailAry.count; i++)
    {
        SizeDetailModel *detailmodel = SizeDetailAry[i];
        NSString *typename = detailmodel.productSizeDetailName;
        UIButton *speciBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth+i*75*displaywidth, h22, 60*displaywidth, 25*displaywidth) ImageName:nil Target:self Action:@selector(speciBtnAction:) Title:typename Font:12.0];
        objc_setAssociatedObject(speciBtn, "firstObject", s_str(detailmodel.ID), OBJC_ASSOCIATION_RETAIN_NONATOMIC);   //实际上就是KVC
        speciBtn.tag = 1000+i;
        NSDictionary *attributes = @{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)};
        CGFloat length = [typename boundingRectWithSize:CGSizeMake(width-20*displaywidth, 25*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
        speciBtn.frame = CGRectMake(15*displaywidth + w22, h22, length + 15*displaywidth , 25*displaywidth);
        if (length > width-20*displaywidth)
        {
            length = width-20*displaywidth;
        }
        if(15*displaywidth + w22 + length + 15*displaywidth > width){
            w22 = 0; //换行时将w置为0
            h22 = h22 + speciBtn.frame.size.height + 10*displaywidth;//距离父视图也变化
            speciBtn.frame = CGRectMake(15*displaywidth + w22, h22, length + 15*displaywidth, 25*displaywidth);//重设button的frame
        }
        w22 = speciBtn.frame.size.width + speciBtn.frame.origin.x;
        UIColor *bordercolor2 = RGB(222, 222, 222);
        UIColor *titcolor2 = RGB(77, 77, 77);
        [speciBtn setTitleColor:titcolor2 forState:UIControlStateNormal];
        speciBtn.layer.cornerRadius = 12.5*displaywidth;
        speciBtn.layer.masksToBounds = YES;
        speciBtn.backgroundColor = bordercolor2;
        [specificationsView addSubview:speciBtn];
        
    }
    h22 += 45*displaywidth;
    specificationsView.frame = CGRectMake(0, classHeight, SCREEN_WIDTH, h22);
    titScrollview.contentSize = CGSizeMake(SCREEN_WIDTH, classHeight+h22+45*displaywidth);
    closeNumView.frame = CGRectMake(0, classHeight+h22, SCREEN_WIDTH, 45*displaywidth);
}

- (void)lookAction
{
    _closeGgView.hidden = YES;
    if ([_csID isEqualToString:@"0"])
    {
        [LTools showMBProgressWithText:@"请选择gui'ge" addToView:self.view];
        return;
    }
    LookParameterViewController *vc = [[LookParameterViewController alloc] init];
    vc.parmerID = _csID;
    [self.navigationController pushViewController:vc animated:YES];
}

//选择规格
- (void)speciBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-1000;
    _csID = objc_getAssociatedObject(btn, "firstObject");
    if (_isProbject)
    {
        lookBtn.hidden = NO;
    }
    for (id v in specificationsView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            UIButton *button = (UIButton *)v;
            [button setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
            button.backgroundColor = RGB(222, 222, 222);
        }
    }
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = ThemeColor;
    if (!_isClose)
    {
        UIButton *classBtn = (UIButton *)[classificationView viewWithTag:500+_classType];
        [classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        classBtn.backgroundColor = ThemeColor;
    }
    if (index != _speciType)
    {
        numTextfield.text = @"1";
    }
    if ([numTextfield.text isEqualToString:@"0"] && index == 0)
    {
        numTextfield.text = @"1";
    }
    _speciType = index;
    _isClose = YES;
    [self tongjiNumberAndMoney];
}

//确定规格
- (void)soureAction
{
    if (_allNumber == 0)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:self.view];
        return;
    }
    [self backGGAction];
    if (_isShopCar)
    {
        [self requestAddShoppingCart];
        
    }
    else
    {
        BuyNowViewController *vc = [[BuyNowViewController alloc] init];
        vc.goodModel = _model;
        vc.goodsDic = _closeGoodsDic;
        vc.zongNum = _allNumber;
        vc.zongPrice = _allPrice;
        vc.zongInteger = _allInteger;
        vc.isTH = _isTeHui;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //    CGFloat X = scrollView.contentOffset.x;
    //    NSInteger index = X/((SCREEN_WIDTH-52*displaywidth)/3);
    //    CGFloat newX = (SCREEN_WIDTH-52*displaywidth)/3*index;
    //    scrollView.contentOffset = CGPointMake(newX, 0);
    
}



- (void)backGGAction
{
    _closeGgView.hidden = YES;
}

-(void)viewTapped:(UITapGestureRecognizer*)tap1
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
}
- (void)jianpanhuishou:(NSNotification *)notification
{
    _closeGgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    _closeGgView.frame = CGRectMake(0, -220*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT);
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == numTextfield && _isClose)
    {
        [self tongjiNumberAndMoney];
    }
}

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
    return indexPath;
}
// 滑动的时候 searchBar 回收键盘

- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_closeGgView endEditing:YES];
    [self.view endEditing:YES];
}


- (void)requestAddShoppingCart
{
    WEAKSELF;
    NSMutableArray *theGgAry = [NSMutableArray arrayWithCapacity:0];
    for (NSString *key in _closeGoodsDic)
    {
        NSDictionary *typeDic = [_closeGoodsDic objectForKey:key];
        for (NSString *key22 in typeDic)
        {
            NSString *numStr = [typeDic objectForKey:key22];
            if ([numStr integerValue] > 0)
            {
                NSDictionary *ggdic = @{@"productSizeDetailId":key22,
                                        @"num":numStr
                                        };
                [theGgAry addObject:ggdic];
            }
        }
    }
    if (theGgAry.count == 0)
    {
        [LTools showMBProgressWithText:@"请选择规格" addToView:self.view];
        return;
    }
    NSDictionary *dic = @{@"productId":_model.ID,
                          @"shoppingCartDetailList":theGgAry
                          };
    [HYBaseHandler requestAddShoppingCartParmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             [LTools showMBProgressWithText:@"添加成功，在购物车等亲哦~" addToView:weakSelf.view];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

- (id)dictionaryWithJsonString:(NSString *)jsonString {
    
    if (jsonString == nil)
    {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
    //    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return jsonObject;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
